<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/conn.asp"-->
<!--#include file="lib/saferequest.asp"-->
<!--#include file="lib/error_write.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="lib/jquery.ui/themes/base/jquery.ui.all.css" />
<link rel="stylesheet" type="text/css" href="lib/yaml/central_draft.css" />
<link rel="stylesheet" type="text/css" href="lib/jQuery.ValidationEngine/css/validationEngine.jquery.css" />
<style type="text/css">
	.ui-datepicker table {
			border: 0;
	}
	#vocc{
		font-family:宋体;
	}
</style>
<script type="text/javascript" src="lib/jquery_lastest.js"></script>
<script type="text/javascript" src="lib/jquery.ui/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="lib/jquery.ui/ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="lib/jquery.ui/ui/i18n/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="lib/jQuery.ValidationEngine/js/jquery.validationEngine-cn.js"></script>
<script type="text/javascript" src="lib/jQuery.ValidationEngine/js/jquery.validationEngine.js"></script>
<script type="text/javascript">
	$(function() {
		//$.datepicker.setDefaults({
		//	changeMonth: true,
		//	changeYear: true
		//});
		$(".datepicker").datepicker({ minDate: 0, maxDate: "+1w" });
		$("#form1").validationEngine();
		//通过选择船公司筛选船名
		$("#vocc").change(function(){
			vocc_id=$(this).val();
			vessel_option='<option disabled="disabled" selected="selected">选择船名</option>';
			$.getJSON("json_vessel_from_vocc_filter.asp",{"vocc_id":vocc_id},function(data){
				$.each(data,function(i,item){
					if(i==0){
						$("#start").attr('value',item.vessel_start);
						$("#end").attr('value',item.vessel_end);
						vessel_option+='<option selected="selected" value="'+item.vessel_id+'">'+item.vessel_name+'</option>';
					}else{
						vessel_option+='<option value="'+item.vessel_id+'">'+item.vessel_name+'</option>';
					}
				});
				$("#vessel").html(vessel_option);
			});
		});
		//通过选择船名筛选船公司
		$("#vessel").change(function(){
			vessel_id=$(this).val();
			$.getJSON("json_select_vocc_from_vessel.asp",{"vessel_id":vessel_id},function(data){
				//alert(data[0].vessel_vocc);
				$("#start").attr('value',data[0].vessel_start);
				$("#end").attr('value',data[0].vessel_end);
				$("#vocc > option").each(function(item){
					if($(this).val()==data[0].vessel_vocc.toString()){
						$(this).attr("selected","selected");
					}
				});
			});
		});
		//提箱、还箱的堆场资料
		//$.getJSON("json_yard.asp",function(data){
		//	yard_option="";
		//	$.each(data,function(i,item){
		//		yard_option+='<option value="'+item.yard_id+'">'+item.yard_name+'</option>';
		//	});
		//	$("#pickup,#return").append(yard_option);
		//});
		//验证提交的数据
		$("#submit").click(function(){
			
		});
	});
</script>	
</head>

<body>
<%
function Voyage_Repeat(voyage_id,voyage_name,voyage_vessel)
	sql="select count(voyage_id) as num from voyage where voyage_name='"&voyage_name&"' and voyage_vessel="&voyage_vessel
	if IsNumeric(voyage_id) and Not IsEmpty(voyage_id) then
		sql=sql&" and voyage_id<>"&voyage_id
	end if
	set rs_repeat=Server.CreateObject("ADODB.Recordset")
	rs_repeat.open sql,conn,1,1
	Voyage_Repeat=rs_repeat("num")
	rs_repeat.close
	set rs_repeat=nothing
end function

voyage_id=Request("voyage_id")
if IsNumeric(voyage_id) and Not IsEmpty(voyage_id) then
	call CheckRights(1,2)
	voyage_id=clng(saferequest("voyage_id",1))
	Set rs = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT * FROM ship where voyage_id="&voyage_id
	rs.Open sql,conn,1,1
	if rs.eof then
		error_write "1","航线不存在"
	else
		'voyage_id=saferequest("voyage_id",1)
		voyage_name=rs("voyage_name")
		voyage_vocc=rs("vocc_id")
		voyage_vessel=rs("voyage_vessel")
		voyage_pickup=rs("voyage_pickup")
		voyage_return=rs("voyage_return")
		voyage_cutoff=rs("voyage_cutoff")
		voyage_sail=rs("voyage_sail")
		voyage_range=rs("voyage_range")
		voyage_berth=rs("voyage_berth")
		voyage_memo=rs("voyage_memo")
		voyage_expires=rs("voyage_expires")
		voyage_start=rs("voyage_start")
		voyage_end=rs("voyage_end")
	end if
end if
If saferequest("mm_voyage",0)="提交" Then
	voyage_name=saferequest("voyage",0)
	voyage_vocc=saferequest("vocc",1)
	voyage_vessel=saferequest("vessel",1)
	voyage_pickup=saferequest("pickup",1)
	voyage_return=saferequest("return",1)
	voyage_cutoff=saferequest("cutoff",0)
	voyage_sail=saferequest("sail",0)
	voyage_range=saferequest("range",1)
	voyage_berth=saferequest("berth",1)
	voyage_memo=saferequest("memo",0)
	voyage_expires=saferequest("expires",0)
	voyage_start=saferequest("start",1)
	voyage_end=saferequest("end",1)
	submit=saferequest("submit",0)
	repeat=Voyage_Repeat(voyage_id,voyage_name,voyage_vessel)
	if repeat>0 then
		error_write "2","航线重复"
	else
		if submit="保存" then
			call CheckRights(1,4)
			sql="update voyage set voyage_name='"&voyage_name&"',voyage_vessel="&voyage_vessel&",voyage_pickup="&voyage_pickup&",voyage_return="&voyage_return&",voyage_cutoff='"&voyage_cutoff&"',voyage_sail='"&voyage_sail&"',voyage_range="&voyage_range&",voyage_berth="&voyage_berth&",voyage_memo='"&voyage_memo&"',voyage_update='"&Now()&"' where voyage_id="&voyage_id
		elseif submit="新增并复制" then
			call CheckRights(1,3)
			sql="insert into voyage(voyage_name,voyage_vessel,voyage_pickup,voyage_return,voyage_cutoff,voyage_sail,voyage_range,voyage_berth,voyage_user,voyage_memo,voyage_expires,voyage_start,voyage_end) values('"&voyage_name&"',"&voyage_vessel&","&voyage_pickup&","&voyage_return&",'"&voyage_cutoff&"','"&voyage_sail&"',"&voyage_range&","&voyage_berth&","&session("MM_ID")&",'"&voyage_memo&"','"&voyage_expires&"',"&voyage_start&","&voyage_end&")"
		end if
	end if
	'response.Write(sql)
	'response.end
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection = conn
	cmd.CommandText = sql
	cmd.Execute
	'cmd.ActiveConnection.Close
end if

%>
<div  class="page_margins">
  <div class="page">
    <div id="nav">

      <div class="hlist">
        <ul>
          <li><a href="ship.asp">船舶信息管理</a></li>
          <li><a href="vocc.html">新增船公司</a></li>
          <li><a href="vessel.html">新增船舶</a></li>
          <li><a href="voyage.asp">新增航次</a></li>
        </ul>
      </div>

    </div>
		<div id="main">
			<div id="col1">
				<form name="form1" method="post" class="yform full" role="application">
					<div class="clearfix">
						<div class="c50l">
							<div class="subcl">
								<fieldset>
									<legend>船舶信息</legend>
									<div class="type-select">
										<label for="vocc">船公司*</label>
										<select name="vocc" id="vocc" aria-required="true">
											<option disabled="disabled" selected="selected">选择船公司</option>
											<%
												Set rs_vocc = Server.CreateObject("ADODB.Recordset")
												sql = "SELECT vocc_id,vocc_name,vocc_chinese  FROM vocc order by vocc_name"
												rs_vocc.Open sql,conn,1,1
												do while not rs_vocc.eof
													vocc_name=rs_vocc("vocc_name")
													u=ulen(vocc_name)
													if u<15 then
														for i=1 to 15-u
															vocc_name=vocc_name&"&nbsp;"
														next
													end if
											%>
											<option value="<%=rs_vocc("vocc_id")%>" <%if rs_vocc("vocc_id")=clng(voyage_vocc) then response.write("selected='selected'")%>><%=vocc_name%><%=rs_vocc("vocc_chinese")%></option>
											<%
													rs_vocc.movenext
												loop
												rs_vocc.close
												set rs_vocc=nothing
											%>
										</select>
									</div>
									<div class="type-select">
										<label for="vessel">船名*</label>
										<select name="vessel" id="vessel" aria-required="true">
											<option disabled="disabled" selected="selected">选择船名</option>
											<%
												Set rs_vessel = Server.CreateObject("ADODB.Recordset")
												sql = "SELECT vessel_id,vessel_name  FROM vessel order by vessel_name"
												rs_vessel.Open sql,conn,1,1
												do while not rs_vessel.eof
											%>
											<option value="<%=rs_vessel("vessel_id")%>" <%if rs_vessel("vessel_id")=clng(voyage_vessel) then response.write("selected='selected'")%>><%=rs_vessel("vessel_name")%></option>
											<%
													rs_vessel.movenext
												loop
												rs_vessel.close
												set rs_vessel=nothing
											%>
										</select>
									</div>
									<div class="type-text">
										<label for="voyage">航次*</label>
										<input name="voyage" id="voyage" aria-required="true" type="text" size="20" value="<%if saferequest("submit",0)="新增并复制" then response.write("") else response.write(voyage_name)%>" />
									</div>
								</fieldset>
							</div>
						</div>
						<div class="c50r">
							<div class="subcr">
								<fieldset>
									<legend>航次信息</legend>
									<div class="c50l">
										<div class="subcl">
											<div class="type-select">
												<label for="pickup">提箱*</label>
												<select name="pickup" id="pickup" aria-required="true">
													<option disabled="disabled" selected="selected">提箱</option>
													<%
														Set rs_yard = Server.CreateObject("ADODB.Recordset")
														sql = "SELECT yard_id,yard_name  FROM yard order by yard_name"
														rs_yard.Open sql,conn,1,1
														do while not rs_yard.eof
													%>
													<option value="<%=rs_yard("yard_id")%>" <%if rs_yard("yard_id")=clng(voyage_pickup) then response.write("selected='selected'")%>><%=rs_yard("yard_name")%></option>
													<%
															rs_yard.movenext
														loop
														rs_yard.close
														set rs_yard=nothing
													%>
												</select>
											</div>
											<div class="type-text">
												<label for="cutoff">截关*</label>
												<input class="datepicker" name="cutoff" id="cutoff" aria-required="true" type="text" size="10" readonly="readonly" value="<%=voyage_cutoff%>" />
											</div>
											<div class="type-text">
												<label for="range">航程*</label>
												<input name="range" id="range" aria-required="true" type="text" size="20" value="<%=voyage_range%>" />
											</div>
											<div class="type-select">
												<label for="start">始发港</label>
												<select name="start" id="start">
													<option value="0" selected="selected">始发港</option>
													<%
														Set rs_start = Server.CreateObject("ADODB.Recordset")
														sql = "SELECT port_id,port_name  FROM port order by port_name"
														rs_start.Open sql,conn,1,1
														do while not rs_start.eof
													%>
													<option value="<%=rs_start("port_id")%>" <%if rs_start("port_id")=clng(voyage_start) then response.write("selected='selected'")%>><%=rs_start("port_name")%></option>
													<%
															rs_start.movenext
														loop
														rs_start.close
														set rs_start=nothing
													%>
												</select>
											</div>
											<div class="type-text">
												<label for="expires">有效期</label>
												<input class="datepicker" name="expires" id="expires" type="text" size="10" readonly="readonly" value="<%if voyage_expires="" then response.write(date()+7) else response.write(voyage_expires)%>" />
											</div>
										</div>
									</div>
									<div class="c50r">
										<div class="subcr">
											<div class="type-select">
												<label for="return">还箱*</label>
												<select name="return" id="return" aria-required="true">
													<option disabled="disabled" selected="selected">还箱</option>
													<%
														Set rs_yard = Server.CreateObject("ADODB.Recordset")
														sql = "SELECT yard_id,yard_name  FROM yard order by yard_name"
														rs_yard.Open sql,conn,1,1
														do while not rs_yard.eof
													%>
													<option value="<%=rs_yard("yard_id")%>" <%if rs_yard("yard_id")=clng(voyage_return) then response.write("selected='selected'")%>><%=rs_yard("yard_name")%></option>
													<%
															rs_yard.movenext
														loop
														rs_yard.close
														set rs_yard=nothing
													%>
												</select>
											</div>
											<div class="type-text">
												<label for="sail">开船*</label>
												<input class="datepicker" name="sail" id="sail" aria-required="true" type="text" size="10" readonly="readonly" value="<%=voyage_sail%>" />
											</div>
											<div class="type-select">
												<label for="berth">泊位*</label>
												<select name="berth" id="berth" aria-required="true">
													<option disabled="disabled" selected="selected">泊位</option>
													<%
														Set rs_berth = Server.CreateObject("ADODB.Recordset")
														sql = "SELECT berth_id,berth_name  FROM berth order by berth_name"
														rs_berth.Open sql,conn,1,1
														do while not rs_berth.eof
													%>
													<option value="<%=rs_berth("berth_id")%>" <%if rs_berth("berth_id")=clng(voyage_berth) then response.write("selected='selected'")%>><%=rs_berth("berth_name")%></option>
													<%
															rs_berth.movenext
														loop
														rs_berth.close
														set rs_berth=nothing
													%>
												</select>
											</div>
											<div class="type-select">
												<label for="end">目的港</label>
												<select name="end" id="end">
													<option value="0" selected="selected">目的港</option>
													<%
														Set rs_end = Server.CreateObject("ADODB.Recordset")
														sql = "SELECT port_id,port_name  FROM port order by port_name"
														rs_end.Open sql,conn,1,1
														do while not rs_end.eof
													%>
													<option value="<%=rs_end("port_id")%>" <%if rs_end("port_id")=clng(voyage_end) then response.write("selected='selected'")%>><%=rs_end("port_name")%></option>
													<%
															rs_end.movenext
														loop
														rs_end.close
														set rs_end=nothing
													%>
												</select>
											</div>
										</div>
									</div>
								</fieldset>
							</div>
						</div>
					</div>
					<div class="type-text">
						<label for="memo">备注</label>
						<textarea name="memo" id="memo"><%=voyage_memo%></textarea>
					</div>
					<div  class="type-button">
						<input type="reset" name="reset" value="重置" />
						<%if Not IsEmpty(voyage_id) then%>
						<input type="submit" name="submit" class="submit" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;
						<%else%>
						<input type="submit" name="submit" class="submit" value="新增并复制" />&nbsp;&nbsp;&nbsp;&nbsp;
						<%end if%>
						<input type="hidden" name="mm_voyage" value="提交" />
<!--						<input type="hidden" name="voyage_id" value="<%=voyage_id%>" /> -->
					</div>
				</form>
				<table id="ship" class="full">
          <thead>
            <tr><th colspan="10" scope="col">添加情况</th></tr>
          </thead>
          <tbody>
            <tr>
              <th scope="col">船名/航次</th>
              <th scope="col">船公司</th>
              <th scope="col">提箱</th>
              <th scope="col">还箱</th>
              <th scope="col">截关</th>
              <th scope="col">开船</th>
              <th scope="col">泊位</th>
              <th scope="col">航程</th>
              <th scope="col">更新时间</th>
              <th scope="col">备注</th>
            </tr>
						<%
							Set rs_new = Server.CreateObject("ADODB.Recordset")
							sql = "SELECT *  FROM ship where voyage_user="&session("MM_ID")&" and DateValue(voyage_update)=date() order by voyage_update desc"
							rs_new.Open sql,conn,1,1
							do while not rs_new.eof
						%>
            <tr>
              <th class="sub" scope="row"><a href="voyage.asp?voyage_id=<%=rs_new("voyage_id")%>"><%=rs_new("vessel_name")%>&nbsp;<%=rs_new("voyage_name")%></a></th>
              <td><%=rs_new("vocc_name")%></td>
              <td><%=rs_new("pickup.yard_name")%></td>
              <td><%=rs_new("return.yard_name")%></td>
              <td><%=rs_new("voyage_cutoff")%></td>
              <td><%=rs_new("voyage_sail")%></td>
              <td><%=rs_new("berth_name")%></td>
              <td><%=rs_new("voyage_range")%></td>
              <td><%=rs_new("voyage_update")%></td>
              <td><%=rs_new("voyage_memo")%></td>
            </tr>
						<%
								rs_new.movenext
							loop
							rs_new.close
							set rs_new=nothing
						%>
          </tbody>
        </table>
			</div>
		</div>
	</div>
</div>
</body>
</html>

